
//author: Changxing Shang
//email: cxshang@gmail.com

//The MIT License (MIT)

//Copyright (c) <2013> <Changxing Shang>

//Permission is hereby granted, free of charge, to any person obtaining a copy
//of this software and associated documentation files (the "Software"), to deal
//in the Software without restriction, including without limitation the rights
//to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
//copies of the Software, and to permit persons to whom the Software is
//furnished to do so, subject to the following conditions:

//The above copyright notice and this permission notice shall be included in
//all copies or substantial portions of the Software.

//THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
//IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
//FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
//AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
//LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
//OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
//THE SOFTWARE.


#include <Python.h>
#include <stdio.h>
#include <string.h>
#include "docitem.h"

int main(int argc, char *argv[]) 
	{
	char tips[]="     ITEM processes graph in undirected, unweighted form. Edgelist must be two values separated with space, and nodes index must start from 0. Indexs of nodes and edges must be sequential without gap. Item can output the resulting communities to a file. In output file, each line is a community which contains some nodes.\nUsages: ./item fn st th\n     In above line, fn is the file name of input network. The st value indicates whether the output indexs starting from 0 or 1. st can only be 0 or 1, the default value is 0. The th value indicates the cut threshold when selecting seeds. The th value must be greater than 2. If the user doesn't provide the th value, it will be determined by item algorithm intelligently.\nExamples:\nitem filename > outputfilename\nitem filename 0 > outputfilename\nitem filename 1 > outputfilename\nitem filename 0 3 > outputfilename\nitem filename 1 4 > outputfilename\n     Noting: when you only give one argument value to item, it must be the filename of network. When you give two arguments to item, the second argument must be st. So, if you want give th a value, you must explicitly give filename and start index value before th value; in other words, all three arguments must be given.\n";
		
		
	if ((argc>4)  || (argc<=1))
		{fprintf(stderr, tips);  exit(1);}
	if (argc>=3)
		{
		if (!(atoi(argv[2]) ==0 || atoi(argv[2]) ==1))
			{fprintf(stderr, tips);  exit(1);}
		}
	if (argc==4)
		{
		if (atoi(argv[3])<=2) 
			{fprintf(stderr, tips);  exit(1);}
		}
		
	fprintf(stderr, "ITEM starting\n");
	Py_Initialize();
	initdocitem();
	if (argc==2)
		item(argv[1],0,0);
	else if  (argc==3)
		item(argv[1],atoi(argv[2]),0);
	else if  (argc==4)
		item(argv[1],atoi(argv[2]),atoi(argv[3]));
	Py_Finalize();
	return 0;
	}
	